﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Globalization;

namespace Rage.UI
{
    public class ModNameConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ItemInstance instance = value as ItemInstance;
            if (instance != null)
            {
                if (parameter.ToString() == "1") return instance.ItemMod1Id != "0" ? instance.ItemMod1.Name : "Empty";
                if (parameter.ToString() == "2") return instance.ItemMod2Id != "0" ? instance.ItemMod2.Name : "Empty";
                if (parameter.ToString() == "3") return instance.ItemMod3Id != "0" ? instance.ItemMod3.Name : "Empty";
                if (parameter.ToString() == "4") return instance.ItemMod4Id != "0" ? instance.ItemMod4.Name : "Empty";
                if (parameter.ToString() == "5") return instance.ItemMod5Id != "0" ? instance.ItemMod5.Name : "Empty";
            }

            return "";
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    public class ModColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ItemSlot itemModType = ItemSlot.None;

            if (value is Item)
            {
                Item item = value as Item;
                if      (parameter.ToString() == "1") itemModType = item.ItemArmoringHiltBarrelType;
                else if (parameter.ToString() == "2") itemModType = item.ItemModType;
                else if (parameter.ToString() == "3") itemModType = item.ItemEnhancementType;
                else if (parameter.ToString() == "4") itemModType = item.ItemColorCrystalType;
                else if (parameter.ToString() == "5") itemModType = item.ItemAugmentType;
            }
            else if (value is ItemInstance)
            {
                ItemInstance instance = value as ItemInstance;
                Item item = instance.Item;
                if      (parameter.ToString() == "1") { if (instance.ItemMod1Id != "0") { itemModType = item.ItemArmoringHiltBarrelType; } }
                else if (parameter.ToString() == "2") { if (instance.ItemMod2Id != "0") { itemModType = item.ItemModType; } }
                else if (parameter.ToString() == "3") { if (instance.ItemMod3Id != "0") { itemModType = item.ItemEnhancementType; } }
                else if (parameter.ToString() == "4") { if (instance.ItemMod4Id != "0") { itemModType = item.ItemColorCrystalType; } }
                else if (parameter.ToString() == "5") { if (instance.ItemMod5Id != "0") { itemModType = item.ItemAugmentType; } }
            }
            
            switch (itemModType)
            {
                case ItemSlot.Armoring: return new SolidColorBrush(Colors.Gray);
                case ItemSlot.Barrel: return new SolidColorBrush(Colors.Orange);
                case ItemSlot.Hilt: return new SolidColorBrush(Colors.Red);
                case ItemSlot.Mod: return new SolidColorBrush(Colors.Yellow);
                case ItemSlot.Enhancement: return new SolidColorBrush(Colors.Green);
                case ItemSlot.ColorCrystal: return new SolidColorBrush(Colors.Blue);
                case ItemSlot.Augment: return new SolidColorBrush(Colors.Purple);
                default:
                    return new SolidColorBrush(Colors.Transparent);
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
